﻿@{
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery-2.0.3.js"></script>
        <script src="~/LiberUI/Scripts/jquery.ba-resize.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Controllers.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
        <script src="~/LiberUI/Scripts/jquery.textSearch-1.0.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.UI.js"></script>
    }
}

<div class="IssueViewItem fladeInDown">
    <span class="IssueNO">#Issue编号</span>
    <span class="IssueImportance"></span>
    <pre class="IssueSummy"></pre>
    <span class="IssuePost"></span>
    <div class="ViewActions">
        <a class="GoDetail" href="#" target="_blank">点击查看详情—></a>
    </div>
</div>

<div id="frmIssue">
    <div id="txbIssueCnt"></div>
    <div id="slcBelongProj" class="Selector"></div>
    <input id="txbProposer" />
    <div id="ratIssueImportance"></div>
</div>

<script>
    wgIssue = {}; //定义命名空间
    wgIssue.tpl_issueView = $(".IssueViewItem").hide().eq(0);

    function makeIssueCard(_issue) {
        var v = wgIssue.tpl_issueView.clone().show();
        v.children(".IssueNO").text(_issue.SerialNum);
        new Rating(v.children(".IssueImportance")).val(_issue.Importance).disable();
        v.children(".IssueSummy").text(_issue.Summy);
        v.children(".IssuePost").text(_issue.Post);
        v.find(".GoDetail").attr('href', '/Issue/Detail?id=' + _issue.IDStr);
        return v;
    };

    wgIssue.onWndShow=function() {
        //显示表单时，设置下拉菜单的Viewer目标和用于设置目标值的事件
        Env.mnuUserProjs.Viewer(wgIssue.frmNewIssue.GetItem(3), wgIssue.setBelongProj);
        Env.mnuProposers.Viewer(wgIssue.frmNewIssue.GetItem(2), wgIssue.setProposer);
        wgIssue.Checker.Enable();
        wgIssue.frmNewIssue.GetItem(0).focus();
    };

    wgIssue.onWndClose=function() {
        wgIssue.Checker.Reset();
        wgIssue.Checker.Disable();
        Env.mnuUserProjs.Menu().hide();
        Env.mnuProposers.Menu().hide();
        Env.mnuProposers.Menu().StopFilter();
    };

    wgIssue.goIssueDetail = function (ev) {
        console.log(ev);
    };

    wgIssue.setBelongProj = function (_viewer, ev) {
        _viewer.val(ev.Data);
    };
    wgIssue.setProposer = function (_viewer, _ev) {
        _viewer.val(_ev.Data);
        wgIssue.Checker.Reset();
    };

    $(function () {
        wgIssue.lstIssueViews = new List(null, { ShowHeader: false, ShowFoot: false,StyleForSlcted:'',StyleForHot:'',Selectble:false,Focusble:false });
        wgIssue.lstIssueViews.af_makeView = function (_data) {
            return makeIssueCard(_data);
        };
        wgIssue.lstIssueViews.on('itemDBClick', wgIssue.goIssueDetail);

        wgIssue.frmNewIssue = new Form($("#frmIssue"));
        wgIssue.frmNewIssue.AddItem("内容描述", new HtmlEditor($("txbIssueCnt")), 'max', true)
                           .AddItem("重急程度", new Rating($("#ratIssueImportance")))
                           .AddItem("提交人", $("#txbProposer"),'',true)
                           .AddItem("所属项目", new ProjViewForSlctor($("#slcBelongProj")));

        wgIssue.frmNewIssue.af_getValue = function (_obj) {
            _obj.Content = this.GetItem(0).val();
            _obj.Importance = this.GetItem(1).val();
            _obj.Proposer = this.GetItem(2).val();
            _obj.Proj = this.GetItem(3).val();
            return _obj;
        };
        wgIssue.frmNewIssue.af_setValue = function (_newValue) {
            this.GetItem(0).val(_newValue.Content);
            this.GetItem(1).val(_newValue.Importance);
            this.GetItem(2).val(_newValue.Proposer);
            this.GetItem(3).val(_newValue.Proj);
        };

        //表单不负责有什么操作，窗体负责提供操作控件
        //创建一个对话窗体来控制Form的显示、隐藏
        wgIssue.WndNewIssue = new Dialoger().on('show', wgIssue.onWndShow).on('hide', wgIssue.onWndClose);
        wgIssue.WndNewIssue.Content(wgIssue.frmNewIssue.dom());

        wgIssue.Checker = new Validater({ BlurOnError: true });
        wgIssue.Checker.NoEmpty(wgIssue.frmNewIssue.GetItem(0), "", "请描述一下事项的主要内容")
                       .NoEmpty(wgIssue.frmNewIssue.GetItem(3), "", "请指定事项的所属项目")
                       .NoEmpty(wgIssue.frmNewIssue.GetItem(2), "", "请填写问题的原始提出人");


        //创建状态切换菜单
        wgIssue.mnuIssueStatus = new PopMenu();
        var lstStatus = new List(null, { ShowHead: false, ShowFoot: false, Selectble: true});
        lstStatus.af_makeView = function (_data) {
            return $("<div>").addClass("slcStatusItem").html(_data);
        };
        lstStatus.Append(['待讨论', '处理中', '中止', '已完成']);
        wgIssue.mnuIssueStatus.Menu(lstStatus, "itemSlcted");
    })
</script>
